from django.db import models
from utils.baseModel import UtilsModel
# Create your models here.
# 菜单表
class Menu_model(UtilsModel):
    # now_status决定是否显示，0表示显示，1表示不显示
    menu_code = models.CharField(max_length=16,  null=False, unique=True, verbose_name='菜单代码')
    tree_name = models.CharField(max_length=24,  null=False, verbose_name='菜单标题')
    href = models.CharField(max_length=255,  null=True, verbose_name='菜单指向')
    fontFamily = models.CharField(max_length=255,  null=False, verbose_name='菜单字体')
    icon = models.CharField(max_length=255,  null=False, verbose_name='菜单icon')
    menu_type = (
        ('01', '目录'),
        ('02', '菜单'),
        ('03', '按钮'),
    )
    menu_marital = models.CharField(choices=menu_type, max_length=16,  null=False, verbose_name='菜单类型')
    spread = models.BooleanField( null=False, default=False, verbose_name='菜单打开')
    menu_pid = models.ForeignKey('self',  null=True, on_delete=models.CASCADE, verbose_name='上级菜单')

    class Meta:
        verbose_name_plural = '菜单表'

    def __str__(self):
        return self.menu_code


# 角色表
class Role_model(UtilsModel):
    role_code = models.CharField(max_length=16,  null=False, unique=True,default=None, verbose_name='角色代码')
    role_name = models.CharField(max_length=255, verbose_name='角色名称',  null=False)
    role_order = models.PositiveIntegerField(verbose_name='排序',  null=False)
    role_byte = models.CharField(max_length=32, verbose_name='权限字符',  null=False)
    role_menu = models.ManyToManyField('Menu_model', verbose_name='角色拥有的菜单')
    per_type = (
        ('01', '全局数据'),
        ('02', '本部门数据'),
        ('03', '本部门及以下数据'),
        ('04', '本人'),
    )
    role_per = models.CharField(choices=per_type, max_length=16,  null=False, default='01', verbose_name='数据权限范围')
    class Meta:
        verbose_name_plural = '角色表'

    def __str__(self):
        return self.role_name

# 机构部门表
class Dept_model(UtilsModel):
    dept_code = models.CharField(max_length=24,  null=False, unique=True, verbose_name='部门编码')
    dept_name = models.CharField(max_length=255,  null=False, verbose_name='部门名称')
    tree_dept = models.ForeignKey('self',null=True, on_delete=models.CASCADE, verbose_name='部门隶属')

    def __str__(self):
        return self.dept_code
    class Meta:
        verbose_name_plural = '部门表'

# 岗位
class Jobs_model(UtilsModel):
    job_code = models.CharField(max_length=24,  null=False, unique=True, verbose_name='岗位编码')
    job_name = models.CharField(max_length=255,  null=False, verbose_name='岗位名称')

    def __str__(self):
        return self.job_code
    class Meta:
        verbose_name_plural = '岗位表'

# 审批设置
class Workflow_model(UtilsModel):
    flow_code = models.CharField(max_length=24,  null=False, unique=True, verbose_name='流程编码')
    flow_name = models.CharField(max_length=255,  null=False, verbose_name='流程名称')
    flow_map = models.TextField(null=False,verbose_name='流程数据')
    flow_perfix = models.CharField(max_length=16,  null=False, verbose_name='前缀')
    flow_year = models.CharField(max_length=4,  null=False, verbose_name='年份')
    flow_suffix = models.PositiveIntegerField(null=False,  verbose_name='生成位数')
    flow_begin = models.PositiveIntegerField(null=False,  default=1, verbose_name='起始参数')
    flow_nownum = models.PositiveIntegerField(null=False,  default=0, verbose_name='业务笔数')
    def __str__(self):
        return self.flow_code

    class Meta:
        verbose_name_plural = '流程表'

